/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-01-28
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-02-25
 * @Description:
 */
import 'package:flutter/material.dart';
import 'package:chat_client/router/router.dart' show navigatorKey;

class ErrorDialog {
  static Future<void> show({
    required String title,
    required String message,
  }) async {
    final context = navigatorKey.currentContext;
    if (context == null) return;
    return showDialog(
      context: context,
      builder: (context) => _DialogContent(title: title, message: message),
    );
  }
}

class _DialogContent extends StatelessWidget {
  final String title;
  final String message;

  const _DialogContent({
    required this.title,
    required this.message,
  });

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ), // 修复括号闭合问题
      title: Text(
        title,
        textAlign: TextAlign.center,
        style: const TextStyle(
          fontSize: 18,
          fontWeight: FontWeight.bold,
        ),
      ),
      contentPadding: const EdgeInsets.symmetric(
        horizontal: 20.0,
        vertical: 10.0,
      ),
      content: SizedBox(
        width: double.infinity, // 确保内容宽度填满
        child: Text(
          message,
          style: const TextStyle(
            color: Color.fromARGB(255, 85, 83, 83),
            overflow: TextOverflow.visible,
          ),
          textAlign: TextAlign.center,
        ),
      ),
      actionsPadding: const EdgeInsets.only(bottom: 8),
      actions: [
        const Divider(height: 1, color: Colors.grey),
        TextButton(
          style: TextButton.styleFrom(
            padding: const EdgeInsets.symmetric(vertical: 12),
            minimumSize: const Size(double.infinity, 48), // 确保按钮全宽
            tapTargetSize: MaterialTapTargetSize.shrinkWrap,
          ),
          onPressed: () => Navigator.pop(context),
          child: const Text('确认'),
        ),
      ],
    );
  }
}
